library(lpirfs)
library(httr)
library(readxl)
library(dplyr)
library(ggplot2)
library(haven)
library(extrafont) 

# Set working directory (replace with your desired path or prompt for user input)
data_dir <- readline(prompt = "Please enter the full path to your data directory: ")
setwd(data_dir)

# Load the data file (you can specify the filename here)
data_file <- file.path(data_dir, "lp_allstd.RData")
load(data_file)

H <- 10
results_panel <-  lp_lin_panel(data_set          = lp_allstd,
                               data_sample       = "Full",
                               cumul_mult        = TRUE,
                               endog_data        = "GDP_growth",
                               shock             = "GDP_growth",
                               diff_shock        = FALSE,
                               
                               panel_model       = "within",
                               panel_effect      = "individual",
                               robust_cov        = "vcovSCC",
                               
                               c_exog_data       = "Finance_sentiment_fd", 
                               l_exog_data       = "Finance_sentiment_fd", "GDP_growth",
                               lags_exog_data    = 3,                               
                               
                               
                               confint           = 1.67,
                               hor               = H + 1)

plot_obj <-plot(results_panel, main=NULL) + labs(title=NULL, y="GDP Growth, ppt", x="Years from shock") +
scale_x_discrete(expand=c(0,0), breaks=seq(0, H, 2), limits = paste0(seq(0, H, 1))) +
  theme(
    text = element_text(size=16),
    axis.title.x = element_text(size=16),
    axis.title.y = element_text(size=16)
  )
pdf("gdps_gdp.pdf")
print(plot_obj)
dev.off()

H <- 10
results_panel <-  lp_lin_panel(data_set          = lp_allstd,
                               data_sample       = "Full",
                               cumul_mult        = TRUE,
                               endog_data        = "GDP_growth",
                               shock             = "Finance_sentiment_fd",
                               diff_shock        = FALSE,
                               
                               panel_model       = "within",
                               panel_effect      = "individual",
                               robust_cov        = "vcovSCC",
                               
                               #c_exog_data       = "Credit_growth",
                               l_exog_data       = "Finance_sentiment_fd", "GDP_growth", 
                               lags_exog_data    = 3,                               
                               
                               
                               confint           = 1.67,
                               hor               = H + 1)

plot_obj <-plot(results_panel, main=NULL) + labs(title=NULL, y="GDP Growth, ppt", x="Years from shock")+
  scale_x_discrete(expand=c(0,0), breaks=seq(0, H, 2), limits = paste0(seq(0, H, 1))) +
  theme(
    text = element_text(size=16),
    axis.title.x = element_text(size=16),
    axis.title.y = element_text(size=16)
  )
pdf("fds_gdp.pdf")
print(plot_obj)
dev.off()






H <- 10
results_panel <-  lp_lin_panel(data_set          = lp_allstd,
                               data_sample       = "Full",
                               cumul_mult        = TRUE,
                               endog_data        = "Finance_sentiment_fd",
                               shock             = "GDP_growth",
                               diff_shock        = FALSE,
                               
                               panel_model       = "within",
                               panel_effect      = "individual",
                               robust_cov        = "vcovSCC",
                               
                               #c_exog_data       = "Credit_growth",
                               l_exog_data       = "Finance_sentiment_fd", "GDP_growth", 
                               lags_exog_data    = 3,                               
                               
                               
                               confint           = 1.67,
                               hor               = H + 1)

plot_obj <-plot(results_panel, main=NULL) + labs(title=NULL, y="Finance Sentiment, ppt", x="Years from shock")+
  scale_x_discrete(expand=c(0,0), breaks=seq(0, H, 2), limits = paste0(seq(0, H, 1))) +
  theme(
    text = element_text(size=16),
    axis.title.x = element_text(size=16),
    axis.title.y = element_text(size=16)
  )
pdf("gdps_fd.pdf")
print(plot_obj)
dev.off()

H <- 10
results_panel <-  lp_lin_panel(data_set          = lp_allstd,
                               data_sample       = "Full",
                               cumul_mult        = TRUE,
                               endog_data        = "Finance_sentiment_fd",
                               shock             = "Finance_sentiment_fd",
                               diff_shock        = FALSE,
                               
                               panel_model       = "within",
                               panel_effect      = "individual",
                               robust_cov        = "vcovSCC",
                               
                               c_exog_data       = "GDP_growth",
                               l_exog_data       = "Finance_sentiment_fd", "GDP_growth", 
                               lags_exog_data    = 3,                               
                               
                               
                               confint           = 1.67,
                               hor               = H + 1)

plot_obj <-plot(results_panel, main=NULL) + labs(title=NULL, y="Finance Sentiment, ppt", x="Years from shock")+
  scale_x_discrete(expand=c(0,0), breaks=seq(0, H, 2), limits = paste0(seq(0, H, 1))) +
  theme(
    text = element_text(size=16),
    axis.title.x = element_text(size=16),
    axis.title.y = element_text(size=16)
  )
pdf("fds_fd.pdf")
print(plot_obj)
dev.off()


